package com.example.servlet.student.tmp;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.BufferedWriter;
import java.io.FileWriter;
import java.io.IOException;

/**
 * @program: sms1
 * @description:
 * @author: zhanghz001
 * @create: 2020-10-30 19:35
 **/
public class StudentServlet extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req, resp);
    }

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        System.out.println("student");
        String username = req.getParameter("username");
        String age = req.getParameter("age");
        String score = req.getParameter("score");

        try (BufferedWriter writer = new BufferedWriter(new FileWriter("I:\\tmp\\student.txt", true));) {

            writer.write(username + "," + age + "," + score);
            writer.newLine();
            resp.getWriter().write("success !!!!");
        } catch (Exception e) {
            e.printStackTrace();
        } finally {

        }
    }
}
